package com.ruoyi.system.interAttr.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.V2.gameAttr.service.IGameAttrTemplateService;
import com.ruoyi.system.interAttr.domain.*;
import com.ruoyi.system.interAttr.mapper.InterAttrMapper;
import com.ruoyi.system.model.domain.GameAttrTemplate;
import com.ruoyi.system.model.domain.GameAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 游戏自定义属性对应模板Controller
 *
 * @author ruoyi
 * @date 2023-04-04
 */
@RestController
@RequestMapping("/inter")
public class InterAttrController extends BaseController {
    @Autowired
    private IGameAttrTemplateService gameAttrTemplateService;

    @Autowired
    private InterAttrMapper interAttrMapper;

    /**
     * 获取游戏字定义属性列表数据
     * @param interAttr
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(InterAttr interAttr){
        List<InterAttr> interAttrs = interAttrMapper.selectInterAttrList(interAttr);
        return  AjaxResult.success(interAttrs);
    }

    /**
     * 获取游戏字定义属性模板西详情
     * @param gameId
     * @param config
     * @return
     */
    @GetMapping("/getInfo")
    public AjaxResult list(Long gameId, String config, String type){
        return  AjaxResult.success(gameAttrTemplateService.selectInfoByConfigIdAndGameId(gameId,config,type));
    }

    /**
     * 查询游戏自定义属性对应模板列表
     */
    @GetMapping("/yuduAttr")
    public AjaxResult yuduAttr(@RequestParam Long gameId, @RequestParam String type) {
        List<GameAttrTemplate> list = gameAttrTemplateService.yuduAttr(gameId,type);

        return AjaxResult.success(list);
    }
    /**
     * 查询游戏自定义属性对应模板列表
     */
    @GetMapping("/yuduCheckAttr")
    public AjaxResult yuduCheckAttr(@RequestParam Long gameId, @RequestParam String type) {
        List<GameAttribute> list = gameAttrTemplateService.yuduCheckAttr(gameId,type);

        return AjaxResult.success(list);
    }
    /**
     * 查询游戏自定义属性对应模板列表
     */
    @GetMapping("/yuduServe")
    public AjaxResult yuduRadio(@RequestParam Long gameId) {
        List<GameAttribute> list = gameAttrTemplateService.yuduServe(gameId);
        return AjaxResult.success(list);
    }


    /**
     * 接口游戏
     */
    @GetMapping("/interGame")
    public AjaxResult interGame(@RequestParam String config) {
        List<GamesRes> list = gameAttrTemplateService.interGame(config);
        return AjaxResult.success(list);
    }
    /**
     * 接口区服
     */
    @GetMapping("/interServers")
    public AjaxResult interServers(@RequestParam String config, @RequestParam String gameId) {
        List<InterServerRes> list = gameAttrTemplateService.interServers(config,gameId);
        return AjaxResult.success(list);
    }

    /**
     * 接口属性
     */
    @GetMapping("/interAttr")
    public AjaxResult interAttr(@RequestParam String gameId, @RequestParam String type, @RequestParam String config) {
        List<InterAttrRes> list = gameAttrTemplateService.interAttr(gameId,type,config);
        return AjaxResult.success(list);
    }

    /**
     * 接口属性
     */
    @GetMapping("/interCheckAttr")
    public AjaxResult interCheckAttr(@RequestParam String gameId, @RequestParam String type, @RequestParam String config) {
        List<InterAttrRes> list = gameAttrTemplateService.interCheckAttr(gameId,type,config);
        return AjaxResult.success(list);
    }


    /**
     * 保存接口游戏
     */
    @GetMapping("/mateGame")
    public AjaxResult mateGame(@RequestParam Map<String,Object> params) {
        gameAttrTemplateService.mateGame(params);
        return AjaxResult.success();
    }


    /**
     * 保存区服
     */
    @PostMapping("/mateServe")
    public AjaxResult mateServe(@RequestBody JSONObject object) {
        gameAttrTemplateService.mateServe(object);
        return AjaxResult.success();
    }

    /**
     * 保存单选项
     */
    @PostMapping("/mateRadio")
    public AjaxResult mateRadio(@RequestBody JSONObject object) {
        gameAttrTemplateService.mateRadio(object);
        return AjaxResult.success();
    }


    /**
     * 保存多选项
     */
    @PostMapping("/mateCheckBox")
    public AjaxResult mateCheckBox(@RequestBody JSONObject object) {
        gameAttrTemplateService.mateCheckBox(object);
        return AjaxResult.success();
    }

    /**
     * 保存输入框
     */
    @PostMapping("/mateInput")
    public AjaxResult mateInput(@RequestBody InterInputReq interInputReqr) {
        gameAttrTemplateService.mateInput(interInputReqr);
        return AjaxResult.success();
    }
    /**
     * 保存输入框
     */
    @PostMapping("/mateOther")
    public AjaxResult mateOther(@RequestBody JSONObject object) {
        gameAttrTemplateService.mateOther(object);
        return AjaxResult.success();
    }

    /**
     * 还差
     * 1、修改接口匹配属性
     * 2、通过渠道id 查询渠道已保存那些属性
     */

    /**
     * 更新
     */
    @PostMapping("/updateInterAttr")
    public AjaxResult updateInterAttr(@RequestBody InterAttr interAttr) {
        gameAttrTemplateService.updateInterAttr(interAttr);
        return AjaxResult.success();
    }

}
